package cn.thread;

public class JoinTest {
    public static void main(String args[]){
        new Thread(new Father()).start();
    }
}
class Father extends Thread{
    @Override
    public void run() {
        System.out.println("父亲想抽烟");
        System.out.println("父亲给儿子钱，买中华");
        Thread t=new Thread(new Son());
        t.start();
        try {
            t.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
            System.out.println("儿子走丢了，父亲去找儿子");
        }
        System.out.println("儿子回来了，把烟给了父亲");
        System.out.println("父亲把零钱给了儿子");

    }
}
class Son extends Thread{
    @Override
    public void run() {
        System.out.println("儿子拿钱去买烟");
        System.out.println("儿子遇到游戏厅，进去了");
        for(int i=0;i<10;i++){
            System.out.println(i+"秒过去了");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("儿子想起去买烟");
        System.out.println("儿子买了中华，回家了");

    }
}
